package cn.rdq.iknesssystem.controller;

import cn.rdq.common.CommonResult;
import cn.rdq.common.file.LocalFileHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/upload")
public class UploadController {

    @Autowired
    private LocalFileHandler localFileHandler;

    @PostMapping("/img")
    public CommonResult uploadImg(@RequestBody MultipartFile file) {
        Map<String, Object> map = new HashMap<>();
        String path = localFileHandler.upload(file);
//        String path = "/upload/2021\\06\\wallhaven-4361p3-d74e8a3e9f0546799440910ff85a14ca.jpg";
        map.put("path", path);
        return CommonResult.successObj(map);
    }

}
